package com.atguigu.pj.partitioner

import org.apache.spark.Partitioner

/**
 * description ： SessionTop10自定义分区器
 * author      ：剧情再美终是戏
 * mail        : 13286520398@163.com
 * date        ：Created in 2020/1/10 16:08
 * modified By ：
 * version:    : 1.0
 */
class SessionTop10Partition(map: Map[String, Int]) extends Partitioner {

  override def numPartitions: Int = map.size

  override def getPartition(key: Any): Int = key match {
    case key: (Long, String) => map.getOrElse(key._1.toString, 0)
    case _ => throw new IllegalArgumentException(s"key type is illegal")
  }
}
